package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.Grogshop;
import cn.wolfcode.trip.base.domain.GrogshopComment;
import cn.wolfcode.trip.base.domain.GrogshopRoom;
import cn.wolfcode.trip.base.query.GrogshopQuery;
import cn.wolfcode.trip.base.service.IGrogshopService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *酒店资源管理控制器
 */
@RestController
@RequestMapping("grogshops")
public class GrogshopController {
    @Autowired
    private IGrogshopService grogshopService;

    /**
     * 根据状态查找酒店
     * 1，资源          grogshops
     * 2，请求方式      get
     * 3,请求参数       state/pageSize
     * 4.返回结果       PageInfo
     * @param
     * @return
     */
    @GetMapping
    public PageInfo query(GrogshopQuery qo,Long desc){
      //判断进行什么排序
       if(desc==null){
           return grogshopService.query(qo);
       }
       else if (desc==1) {
            qo.setOrderBy("g.price desc");
       }else if (desc==2){
            qo.setOrderBy("g.price");
       } else if (desc==3){
            qo.setOrderBy("g.grade desc");
       }else if (desc==4){
            qo.setOrderBy("g.grade");
       }

        return grogshopService.query(qo);
    }

    /**
     * 根据酒店的id查询预订信息
     * 1，资源           grogshops/{id}/room
     * 2,请求方式        get
     * 3,请求参数        id
     * 4,返回结果        Grogshop
     * @param id
     * @return
     */
    @GetMapping("{id}/room")
    public List<Grogshop> getGrogshopById(@PathVariable Long id){

        return grogshopService.getGrogshopById(id);
    }

    /**
     * 根据酒店的id查询文章内容
     * 1，资源           grogshops/{id}/comment
     * 2,请求方式        get
     * 3,请求参数        id
     * 4,返回结果        Grogshop
     * @param id
     * @return
     */
    @GetMapping("{id}/comment")
    public GrogshopComment getCommetnById(@PathVariable Long id){

        return grogshopService.getCommetnById(id);
    }

}
